<div class="page" loaded="bindEntityInfo">
	<div class="pageContent">
		<form id="pageAdd" type="post" action="category/{category_id}/entity" class="pageForm required-validate" onsubmit="return validateCallback(this, dialogAjaxDone);">
			<div class="pageFormContent" layoutH="57" category_id="{category_id}" sign="{entity}">
				<fieldset>
					<legend>基本信息</legend>
					<div class="unit">
						<label>标题：</label> <input class="textInputRequired required" type="text" size="30" name="title" focus="true" alt="请输入标题" />
					</div>
					<!-- 屏蔽文件上传，内容编辑和url填写，需要时可以放开隐藏使用-->
					<div class="unit" style="display: none">
						<label>图片：</label> <span> <img name="picture" src="" oldpath="" /> <input name="file_id" type="hidden" size="30" value="0" /> <a href="javascript:;"
							url="multiupload/multiupload.html?ext=图片文件(*.jpg;*.gif;*.png;*.bmp;*.jpeg)&count=1&size=500 KB" target="dialog" rel="multiupload" iframe="true" mask="true" width="400"
							height="300" callback="uploadEntityPic">上传文件</a>
						</span>
					</div>
					<div class="unit" style="display: none">
						<label>URL地址：</label> <input class="url" name="url" type="text" size="30" />
					</div>
					<p>
						<span style="margin-left: 5px">可编辑： </span><span><input type="radio" name="islock" checked="checked" value=0 /></span> <span style="margin-left: 25px">锁定： </span><span><input
							type="radio" name="islock" value=1 /></span>
					</p>
					<p>
						<span style="margin-left: 5px">不指派： </span><span><input type="radio" name="ontop" checked="checked" value=0 /></span> <span style="margin-left: 25px">指派： </span><span><input
							type="radio" name="ontop" value=1 /></span>
					</p>
					<div class="textareaBar" style="display: none">
						<label>内容：</label>
						<textarea class="editor"
							tools="{tools:'mfull',upBtnText:'上传',upImgUrl:'/services/file',upImgExt:'jpg,jpeg,gif,png',upFlashUrl:'/services/file',upFlvUrl:'/services/file',upMediaUrl:'/services/file',upMediaExt:'wmv,avi,wma'}"
							name="content" rows="5" style="width: 100%">内容</textarea>
					</div>
				</fieldset>
				<input type="hidden" id="value" name="value" /> <input type="hidden" name="used_fields" />
			</div>
			<div class="formBar">
				<ul>
					<li><div class="buttonActive">
							<div class="buttonContent">
								<button type="submit" class="ok" onclick="setAttributeValueForAdd();">提交</button>
							</div>
						</div></li>
					<li><div class="button">
							<div class="buttonContent">
								<button type="button" class="close">取消</button>
							</div>
						</div></li>
				</ul>
			</div>
		</form>
	</div>
</div>
<script>
	function uploadEntityPic(msg, $dom) {
		var content = $dom.parents(".pageFormContent");
		$("img[name=picture]", content).attr("src", msg[0].small).click(function() {
			var win = window.open("about:blank");
			win.document.body.innerHTML = '<img src="'+msg[0].origin+'" />';
		});//.attr("oldpath",msg[0].origin);
		$("input[name=file_id]", content).val(msg[0].file_id);
		//alert($("input[name=file_id]",content).val());
		//alert($("img[name=picture]",content).attr("src"));
	}

	function bindEntityInfo($dom) {
		var $cont = $(".pageFormContent", $dom);
		var sign = $cont.attr("sign");
		if (sign != "document") { //车管所项目中，只有项目管理才有指派
			$("div[name=ontopDiv]").hide();
		}
		bindExtField($cont, "add");
	}

	/**
	 * 组装扩展属性，将扩展属性的值以json格式保存在value对象中
	 * eg:[{'type_id':'1','detail_value':[{'title':'档案编号','value':'12','attribute_id':'1'},{'title':'项目编号','value':'12','attribute_id':'2'}]}]
	 */
	function setAttributeValueForAdd() {
		var submitValue = "[";

		//组装提交到后台的value数据
		var typeArr = $("fieldset[typeId]");
		if (typeArr.length == 0) {
			return;
		}
		$.each(typeArr, function(i, type) {
			var typeId = $(type).attr("typeId");
			submitValue = submitValue + "{'type_id':'" + typeId + "','detail_value':[";

			var contentArr = $("fieldset[typeId=" + typeId + "] div[name='inputdiv']");
			$.each(contentArr, function(j, content) {
				var title = $(content).find("label").attr("outerText").replace("：", "");
				var val = $(content).find("input").val();
				var attr = $(content).find("input").attr("name").replace("attr_id_", "");
				submitValue = submitValue + "{'title':'" + title + "','value':'" + val + "','attribute_id':'" + attr + "'},";
			});
			submitValue = submitValue.substr(0, submitValue.lastIndexOf(",")) + "]},";
		});
		submitValue = submitValue.substr(0, submitValue.lastIndexOf(",")) + "]";
		$("#value").val(submitValue);
	}
</script>